<?php
class ChidoancbsController extends AppController {

	var $name = 'Chidoancbs';

	function index() {
		$this->Chidoancb->recursive = 0;
		$this->set('chidoancbs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid chidoancb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('chidoancb', $this->Chidoancb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Chidoancb->create();
			if ($this->Chidoancb->save($this->data)) {
				$this->Session->setFlash(__('The chidoancb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chidoancb could not be saved. Please, try again.', true));
			}
		}
		$khoas = $this->Chidoancb->Khoa->find('list');
		$this->set(compact('khoas'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid chidoancb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Chidoancb->save($this->data)) {
				$this->Session->setFlash(__('The chidoancb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chidoancb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Chidoancb->read(null, $id);
		}
		$khoas = $this->Chidoancb->Khoa->find('list');
		$this->set(compact('khoas'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for chidoancb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Chidoancb->delete($id)) {
			$this->Session->setFlash(__('Chidoancb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Chidoancb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>